truncate table account_number
GO

truncate table article
GO

Truncate table document
go

truncate table user_company
Go

truncate table company_address
Go

ALTER TABLE [dbo].[account_number] DROP CONSTRAINT [FK_account_number_company_bank]
GO
DROP INDEX [ID_bank] ON [dbo].[company_bank]
GO
DROP INDEX [ID_company] ON [dbo].[company_bank]
GO
ALTER TABLE [dbo].[company_bank] DROP CONSTRAINT [company_bank_FK00]
GO
ALTER TABLE [dbo].[company_bank] DROP CONSTRAINT [company_bank_FK01]
GO
ALTER TABLE [dbo].[company_bank] DROP CONSTRAINT [DF_company_bank_Created]
GO
truncate table company_bank
Go
ALTER TABLE [dbo].[company_bank] ADD  CONSTRAINT [DF_company_bank_Created]  DEFAULT (getdate()) FOR [Created]
GO
ALTER TABLE [dbo].[company_bank]  WITH CHECK ADD  CONSTRAINT [company_bank_FK01] FOREIGN KEY([ID_company])
REFERENCES [dbo].[company] ([ID])
GO
ALTER TABLE [dbo].[company_bank] CHECK CONSTRAINT [company_bank_FK01]
GO
ALTER TABLE [dbo].[company_bank]  WITH CHECK ADD  CONSTRAINT [company_bank_FK00] FOREIGN KEY([ID_bank])
REFERENCES [dbo].[bank] ([ID])
GO
ALTER TABLE [dbo].[company_bank] CHECK CONSTRAINT [company_bank_FK00]
GO
CREATE NONCLUSTERED INDEX [ID_bank] ON [dbo].[company_bank]
(
	[ID_bank] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [ID_company] ON [dbo].[company_bank]
(
	[ID_company] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
ALTER TABLE [dbo].[account_number]  WITH CHECK ADD  CONSTRAINT [FK_account_number_company_bank] FOREIGN KEY([ID_company_bank])
REFERENCES [dbo].[company_bank] ([ID])
GO
ALTER TABLE [dbo].[account_number] CHECK CONSTRAINT [FK_account_number_company_bank]
GO


ALTER TABLE [dbo].[document] DROP CONSTRAINT [FK_document_company]
GO
ALTER TABLE [dbo].[document] DROP CONSTRAINT [FK_document_company1]
GO
ALTER TABLE [dbo].[company_bank] DROP CONSTRAINT [company_bank_FK01]
GO
ALTER TABLE [dbo].[company_address] DROP CONSTRAINT [company_address_FK00]
GO
ALTER TABLE [dbo].[user_company] DROP CONSTRAINT [FK_user_company_company]
GO
ALTER TABLE [dbo].[company] DROP CONSTRAINT [DF__company__company__1FCDBCEB]
GO
ALTER TABLE [dbo].[company] DROP CONSTRAINT [DF_company_Created]
GO
truncate table company
Go
ALTER TABLE [dbo].[company] ADD  CONSTRAINT [DF__company__company__1FCDBCEB]  DEFAULT ((0)) FOR [company_vat]
GO
ALTER TABLE [dbo].[company] ADD  CONSTRAINT [DF_company_Created]  DEFAULT (getdate()) FOR [Created]
GO
ALTER TABLE [dbo].[user_company]  WITH CHECK ADD  CONSTRAINT [FK_user_company_company] FOREIGN KEY([ID_company])
REFERENCES [dbo].[company] ([ID])
GO
ALTER TABLE [dbo].[user_company] CHECK CONSTRAINT [FK_user_company_company]
GO
ALTER TABLE [dbo].[company_address]  WITH CHECK ADD  CONSTRAINT [company_address_FK00] FOREIGN KEY([ID_company])
REFERENCES [dbo].[company] ([ID])
GO
ALTER TABLE [dbo].[company_address] CHECK CONSTRAINT [company_address_FK00]
GO
ALTER TABLE [dbo].[company_bank]  WITH CHECK ADD  CONSTRAINT [company_bank_FK01] FOREIGN KEY([ID_company])
REFERENCES [dbo].[company] ([ID])
GO
ALTER TABLE [dbo].[company_bank] CHECK CONSTRAINT [company_bank_FK01]
GO
ALTER TABLE [dbo].[document]  WITH CHECK ADD  CONSTRAINT [FK_document_company] FOREIGN KEY([ID_company_issued_by])
REFERENCES [dbo].[company] ([ID])
GO
ALTER TABLE [dbo].[document] CHECK CONSTRAINT [FK_document_company]
GO
ALTER TABLE [dbo].[document]  WITH CHECK ADD  CONSTRAINT [FK_document_company1] FOREIGN KEY([ID_client_issued_to])
REFERENCES [dbo].[company] ([ID])
GO
ALTER TABLE [dbo].[document] CHECK CONSTRAINT [FK_document_company1]
GO

ALTER TABLE [dbo].[user_company] DROP CONSTRAINT [FK_user_company_users]
GO
truncate table users
ALTER TABLE [dbo].[user_company]  WITH CHECK ADD  CONSTRAINT [FK_user_company_users] FOREIGN KEY([ID_user])
REFERENCES [dbo].[users] ([ID])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[user_company] CHECK CONSTRAINT [FK_user_company_users]
GO